using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public class ValueBll
{
    DBAccess db = new DBAccess();

    public ValueBll()
    {

    }

    public DataTable getAllValue()
    {
        return db.executeSelect("GetAllValue");
    }

    public DataTable getValueById(int valueId)
    {
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@ValueId", SqlDbType.Int);
        para[0].Value = valueId;
        return db.executeSelect("GetValueById", para);
    }

    public DataTable getValueByInsuranceId(int insuranceId)
    {
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@InsuranceId", SqlDbType.Int);
        para[0].Value = insuranceId;
        return db.executeSelect("GetValueByInsuranceId", para);
    }

    public bool insertValue(Value val)
    {
        bool result;
        SqlParameter[] para = new SqlParameter[3];
        para[0] = new SqlParameter("@InsuranceId", SqlDbType.Int);
        para[0].Value = val.InsuranceId;
        para[1] = new SqlParameter("@ValueType", SqlDbType.NVarChar);
        para[1].Value = val.ValueType;
        para[2] = new SqlParameter("@Price", SqlDbType.Int);
        para[2].Value = val.Price; 
        if (db.execute("InsertValue", para) > 0)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        return result;
    }

    public bool updateValueById(Value val)
    {
        bool result;
        SqlParameter[] para = new SqlParameter[3];
        para[0] = new SqlParameter("@ValueID", SqlDbType.Int);
        para[0].Value = val.ValueId;
        para[1] = new SqlParameter("@ValueType", SqlDbType.NVarChar);
        para[1].Value = val.ValueType;
        para[2] = new SqlParameter("@Price", SqlDbType.Int);
        para[2].Value = val.Price;
        if (db.execute("UpdateValueById", para) > 0)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        return result;
    }

    public bool deleteValueById(int ValueId)
    {
        bool result;
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@ValueId", SqlDbType.Int);
        para[0].Value = ValueId;
        if (db.execute("DeleteValueById", para) > 0)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        return result;
    }

    public bool deleteValueByInsuranceId(int insuranceId)
    {
        bool result;
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@InsuranceId", SqlDbType.Int);
        para[0].Value = insuranceId;
        if (db.execute("DeleteValueByInsuranceId", para) > 0)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        return result;
    }
}
